<template>
    <div>
        <h1>添加房号</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <th align="right">房型名称</th>
                    <th>
                        <select v-model="queryinfo.NType">
                            <option value="">请选择</option>
                            <option :value="item.HName" v-for="item in list">{{ item.HName }}</option>
                        </select>
                    </th>
                </tr>
                <tr>
                    <th align="right">房间号码</th>
                    <th><input type="text" v-model="queryinfo.Num"></th>
                </tr>
                <tr>
                    <th align="right">房号描述</th>
                    <th>
                        <textarea cols="50" rows="5" v-model="queryinfo.NDesc"></textarea>
                    </th>
                </tr>
                <tr>
                    <th align="right">状态</th>
                    <th>
                        <input type="radio" name="state" :value="1" v-model="queryinfo.NState">上架
                        <input type="radio" name="state" :value="0" v-model="queryinfo.NState">下架
                    </th>
                </tr>
                <tr>
                    <th align="right"></th>
                    <th><input type="button" value="增加" class="btn btn-primary" @click="ok"></th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
import { useAdminStare } from '@/stores/admin';
const adc = useAdminStare();
const route = useRoute()
const router = useRouter()

let queryinfo:any=reactive({
  "NType": "",
  "Num": "",
  "NDesc": "",
  "NState": 1,
})

let list:any=ref([])

onMounted(()=>{
    getist()
})

const getist=()=>{
    axios({
        url:'/api/House/GetHouseTypes',
        method:'get',
    })
    .then((res)=>{
        console.log(res);
        list.value=res.data
    })
}

const ok=()=>{
    axios({
        url:'/api/House/AddHouseNumber',
        method:'post',
        data:queryinfo
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0){
            alert("添加成功")

        }
        else{
            alert("添加失败")
            return
        }
    })
}

</script>

<style scoped>

</style>